package com.br.estoque.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.br.estoque.bean.Marca;

public class MarcaDAO extends DataUtils {
	
	public List<Marca> getAll(){
		Connection conn = null;
		PreparedStatement stmt = null;
		Marca marca = null;
		List<Marca> listaMarca = new ArrayList<Marca>();
		ResultSet rs = null;
		
		try{
			conn = getConnection();
			stmt = conn.prepareStatement("SELECT * FROM estoque.marca;");
			rs  = stmt.executeQuery();
			while(rs.next()){
				marca = new Marca();
				marca.setId(rs.getInt("codigo"));
				marca.setMarca(rs.getString("marca"));
				listaMarca.add(marca);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				conn.close();
				stmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return listaMarca;
	}
}
